package org.autumn.lock;

import java.util.concurrent.Callable;
import java.util.concurrent.Executors;
import java.util.concurrent.TimeUnit;

public class WaitMethod {
    private static Object LOCK = new Object();
    public static void main(String[] args) throws InterruptedException {
        new Thread(() -> {
            synchronized (LOCK){
                try {
                    LOCK.wait();

                    System.out.println("t1 wake up ...");
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }
            }
        }, "t1").start();

        new Thread(() -> {
            synchronized (LOCK){
                try {
                    LOCK.wait();

                    System.out.println("t2 wake up ...");
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }
            }
        }, "t2").start();


        TimeUnit.SECONDS.sleep(2);
        System.out.println("main thread start wake up ...");
        synchronized (LOCK){
//            LOCK.notify();
            LOCK.notifyAll();
        }

    }
}
